home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
libgutil
/
bm.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
3KB
|
130 lines
/*
* Copyright 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* Simple support for bitmap reading.
*
*
* exports
*
void bmopen(name,mode,xsize,ysize)
void bmputrow(buf)
void bmgetrow(buf)
int bmrowbytes()
void bmsize(xsize,ysize)
void bmclose()
*
*/
#include "stdio.h"
#include "bitmap.h"
static Bitmap b;
static FILE *bmfile;
static int bytesperrow;
#define BMMAGIC 0x5421
void bmopen(name,mode,xsize,ysize)
char *name;
char *mode;
int xsize, ysize;
{
long magic[2];
if(mode[0] == 'r') {
bmfile = fopen(name,"r");
if(!bmfile) {
fprintf(stderr,"bmopen: can't open input file %s\n",name);
exit(1);
}
fread(magic,2*sizeof(long),1,bmfile);
if(magic[0] != BMMAGIC || magic[1] != BMMAGIC) {
fprintf(stderr,"bmopen: bad magic number in bit map header\n");
exit(1);
}
fread(&b.base,sizeof(short *),1,bmfile);
fread(&b.xsize,sizeof(short),1,bmfile);
fread(&b.ysize,sizeof(short),1,bmfile);
fread(&b.xorig,sizeof(short),1,bmfile);
fread(&b.yorig,sizeof(short),1,bmfile);
fread(&b.xmove,sizeof(short),1,bmfile);
fread(&b.ymove,sizeof(short),1,bmfile);
fread(&b.sper,sizeof(short),1,bmfile);
bytesperrow = 2*b.sper;
} else if(mode[0] == 'w') {
long magic[2];
Bitmap b;
b.xsize = xsize;
b.ysize = ysize;
b.xorig = 0;
b.yorig = 0;
b.xmove = 0;
b.ymove = 0;
b.sper = 1+((xsize-1)>>4);
b.base = 0;
bmfile = fopen(name,"w");
if(!bmfile) {
fprintf(stderr,"bmopen: can't open output file %s\n",name);
exit(1);
}
magic[0] = BMMAGIC;
magic[1] = BMMAGIC;
fwrite(magic,2*sizeof(long),1,bmfile);
fwrite(&b.base,sizeof(short *),1,bmfile);
fwrite(&b.xsize,sizeof(short),1,bmfile);
fwrite(&b.ysize,sizeof(short),1,bmfile);
fwrite(&b.xorig,sizeof(short),1,bmfile);
fwrite(&b.yorig,sizeof(short),1,bmfile);
fwrite(&b.xmove,sizeof(short),1,bmfile);
fwrite(&b.ymove,sizeof(short),1,bmfile);
fwrite(&b.sper,sizeof(short),1,bmfile);
bytesperrow = 2*b.sper;
} else {
fprintf(stderr,"bmopen: bad mode %s\n",mode);
exit(1);
}
}
void bmputrow(buf)
char *buf;
{
fwrite(buf,bytesperrow,1,bmfile);
}
void bmgetrow(buf)
char *buf;
{
fread(buf,bytesperrow,1,bmfile);
}
int bmrowbytes()
{
return bytesperrow;
}
void bmsize(xsize,ysize)
int *xsize, *ysize;
{
*xsize = b.xsize;
*ysize = b.ysize;
}
void bmclose()
{
fclose(bmfile);
}